\hypertarget{bus_8c}{
\section{wmv\_\-bus/bus.c File Reference}
\label{bus_8c}\index{wmv\_\-bus/bus.c@{wmv\_\-bus/bus.c}}
}
The communication bus protocol used in the openASC project.  


{\tt \#include $<$stdio.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$avr/wdt.h$>$}\par
{\tt \#include $<$avr/io.h$>$}\par
{\tt \#include $<$avr/interrupt.h$>$}\par
{\tt \#include \char`\"{}bus.h\char`\"{}}\par
{\tt \#include \char`\"{}bus\_\-tx\_\-queue.h\char`\"{}}\par
{\tt \#include \char`\"{}bus\_\-rx\_\-queue.h\char`\"{}}\par
{\tt \#include \char`\"{}bus\_\-commands.h\char`\"{}}\par
{\tt \#include \char`\"{}bus\_\-ping.h\char`\"{}}\par
{\tt \#include \char`\"{}global.h\char`\"{}}\par
{\tt \#include \char`\"{}bus\_\-usart.h\char`\"{}}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
\hypertarget{bus_8c_66e8708f99633602ea17873c9bed4b6d}{
void \hyperlink{bus_8c_66e8708f99633602ea17873c9bed4b6d}{bus\_\-init} (void)}
\label{bus_8c_66e8708f99633602ea17873c9bed4b6d}

\begin{CompactList}\small\item\em Init the communication bus. \item\end{CompactList}\item 
void \hyperlink{bus_8c_9869a6434da36c0bfa8573d68bed9b40}{bus\_\-set\_\-address} (unsigned char addr)
\begin{CompactList}\small\item\em Set the address of this device on the bus. \item\end{CompactList}\item 
unsigned char \hyperlink{bus_8c_ceb215ff9ef4810ef00434c1c02f6a4c}{bus\_\-allowed\_\-to\_\-send} (void)
\begin{CompactList}\small\item\em Returns if you are allowed to transmit data to the bus or not. \item\end{CompactList}\item 
unsigned char \hyperlink{bus_8c_978d35e07c79199b121997d80de56655}{bus\_\-get\_\-address} (void)
\begin{CompactList}\small\item\em Returns the address of this device. \item\end{CompactList}\item 
\hypertarget{bus_8c_e17905990a3f145d02f7390f7c7676af}{
void \hyperlink{bus_8c_e17905990a3f145d02f7390f7c7676af}{bus\_\-send\_\-message} (void)}
\label{bus_8c_e17905990a3f145d02f7390f7c7676af}

\begin{CompactList}\small\item\em Sends the first message in the FIFO TX queue to the communication bus. \item\end{CompactList}\item 
\hypertarget{bus_8c_1f8ed281f15b4e6e34cdcdb2bfb70932}{
void \_\-\_\-inline\_\-\_\- \hyperlink{bus_8c_1f8ed281f15b4e6e34cdcdb2bfb70932}{bus\_\-reset\_\-tx\_\-status} (void)}
\label{bus_8c_1f8ed281f15b4e6e34cdcdb2bfb70932}

\begin{CompactList}\small\item\em Function that resets the bus status variables. \item\end{CompactList}\item 
\hypertarget{bus_8c_524ab9ee02e43dff455677fdecfb5e21}{
void \_\-\_\-inline\_\-\_\- \hyperlink{bus_8c_524ab9ee02e43dff455677fdecfb5e21}{bus\_\-reset\_\-rx\_\-status} (void)}
\label{bus_8c_524ab9ee02e43dff455677fdecfb5e21}

\begin{CompactList}\small\item\em Function that resets the bus status variables. \item\end{CompactList}\item 
unsigned char \hyperlink{bus_8c_ce52a77ee7a62558643de23c5f10f9c7}{bus\_\-is\_\-master} (void)
\begin{CompactList}\small\item\em Returns if the bus is set to be master. \item\end{CompactList}\item 
void \hyperlink{bus_8c_ed493aabe32ac3eaafb77d4c23f15eb9}{bus\_\-set\_\-is\_\-master} (unsigned char state, unsigned char count)
\begin{CompactList}\small\item\em Set the status if the device should be master or not. \item\end{CompactList}\item 
void \hyperlink{bus_8c_651be0f483dc1e17174069bbf991d653}{bus\_\-send\_\-nack} (unsigned char to\_\-addr, unsigned char error\_\-type)
\begin{CompactList}\small\item\em Send an NOT acknowledge. \item\end{CompactList}\item 
\hypertarget{bus_8c_069826b2c00193de5883c42ffc8c95fc}{
void \hyperlink{bus_8c_069826b2c00193de5883c42ffc8c95fc}{bus\_\-send\_\-ack} (unsigned char to\_\-addr)}
\label{bus_8c_069826b2c00193de5883c42ffc8c95fc}

\begin{CompactList}\small\item\em Send an acknowledge. \item\end{CompactList}\item 
unsigned char \hyperlink{bus_8c_76f9639571632344a2a1ae4138663667}{bus\_\-get\_\-device\_\-count} (void)
\begin{CompactList}\small\item\em Receive the device count on the bus. \item\end{CompactList}\item 
void \hyperlink{bus_8c_bbcb4456ec66651e191189cc985bfeab}{bus\_\-set\_\-device\_\-count} (unsigned char \hyperlink{front__panel_2main_8c_4e659bfe570f8e58593672bc9a8d22a7}{device\_\-count})
\begin{CompactList}\small\item\em Set the number of devices that are on the bus. \item\end{CompactList}\item 
\hypertarget{bus_8c_2e40ef066b1f7231f314bc85779110ed}{
void \hyperlink{bus_8c_2e40ef066b1f7231f314bc85779110ed}{bus\_\-resend\_\-message} (void)}
\label{bus_8c_2e40ef066b1f7231f314bc85779110ed}

\begin{CompactList}\small\item\em Resend the last message. \item\end{CompactList}\item 
\hypertarget{bus_8c_370f257e97b9adc5aeb57ef539ce8547}{
void \hyperlink{bus_8c_370f257e97b9adc5aeb57ef539ce8547}{bus\_\-check\_\-tx\_\-status} (void)}
\label{bus_8c_370f257e97b9adc5aeb57ef539ce8547}

\begin{CompactList}\small\item\em Checks if there is anything that should be sent in the TX queue. \item\end{CompactList}\item 
void \hyperlink{bus_8c_4c78398b39ca1a317bcd94e32d3238ed}{bus\_\-add\_\-tx\_\-message} (unsigned char from\_\-addr, unsigned char to\_\-addr, unsigned char flags, unsigned char cmd, unsigned char length, unsigned char data\mbox{[}$\,$\mbox{]})
\begin{CompactList}\small\item\em Adds a message to the TX queue which will be sent as soon as possible. \item\end{CompactList}\item 
void \hyperlink{bus_8c_8900b6684889df452076e67b3a528bc8}{bus\_\-add\_\-rx\_\-message} (unsigned char from\_\-addr, unsigned char to\_\-addr, unsigned char flags, unsigned char cmd, unsigned char length, unsigned char data\mbox{[}$\,$\mbox{]})
\begin{CompactList}\small\item\em Adds a message to the RX queue which will be sent as soon as possible. \item\end{CompactList}\item 
\hypertarget{bus_8c_d6dee76884c2faaaec40ea32a460600c}{
void \hyperlink{bus_8c_d6dee76884c2faaaec40ea32a460600c}{bus\_\-add\_\-new\_\-message} (void)}
\label{bus_8c_d6dee76884c2faaaec40ea32a460600c}

\begin{CompactList}\small\item\em Adds the message bus\_\-new\_\-message into the RX queue. \item\end{CompactList}\item 
void \hyperlink{bus_8c_4541ef9a75addac3aaa4af88d8f03590}{bus\_\-message\_\-nacked} (unsigned char addr, unsigned char error\_\-type)
\begin{CompactList}\small\item\em The message last sent was NACKED from the receiver. \item\end{CompactList}\item 
\hypertarget{bus_8c_205fdad7d74dbd67e7b31c9630819cb9}{
void \hyperlink{bus_8c_205fdad7d74dbd67e7b31c9630819cb9}{bus\_\-message\_\-acked} (unsigned char addr)}
\label{bus_8c_205fdad7d74dbd67e7b31c9630819cb9}

\begin{CompactList}\small\item\em The message last sent was acknowledged from the receiver. \item\end{CompactList}\item 
\hyperlink{bus_8c_56c7d1c90fd3b9b05b882677670d151e}{ISR} (ISR\_\-BUS\_\-USART\_\-DATA)
\item 
\hyperlink{bus_8c_4ea7bd97e74a54718958107b4d2da063}{ISR} (ISR\_\-BUS\_\-USART\_\-RECV)
\item 
\hyperlink{bus_8c_efcb4b9972f80d02e113869d694b4aab}{ISR} (ISR\_\-BUS\_\-USART\_\-TRANS)
\item 
\hyperlink{bus_8c_90fe1670ecc0478c38c6903ffa1fb1ac}{ISR} (ISR\_\-BUS\_\-TIMER\_\-COMPARE)
\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
\hypertarget{bus_8c_84490b82413d551e70a48596f334f0b0}{
\hyperlink{structbus__status__struct}{bus\_\-status\_\-struct} \hyperlink{bus_8c_84490b82413d551e70a48596f334f0b0}{bus\_\-status}}
\label{bus_8c_84490b82413d551e70a48596f334f0b0}

\begin{CompactList}\small\item\em The bus status structure. \item\end{CompactList}\item 
\hypertarget{bus_8c_cd52bf6c724f70eaa5816bdaed78749b}{
unsigned char \hyperlink{bus_8c_cd52bf6c724f70eaa5816bdaed78749b}{calc\_\-checksum} = 0}
\label{bus_8c_cd52bf6c724f70eaa5816bdaed78749b}

\begin{CompactList}\small\item\em Variable used to calculate the checksum when receiving a message. \item\end{CompactList}\item 
\hypertarget{bus_8c_caaf7c4fe8a90cd7e2f50cdcaf6cdb6a}{
\hyperlink{structBUS__MESSAGE}{BUS\_\-MESSAGE} \hyperlink{bus_8c_caaf7c4fe8a90cd7e2f50cdcaf6cdb6a}{bus\_\-new\_\-message}}
\label{bus_8c_caaf7c4fe8a90cd7e2f50cdcaf6cdb6a}

\begin{CompactList}\small\item\em The new message. \item\end{CompactList}\item 
\hypertarget{bus_8c_025b74f1b48eb3c20b99a7158fb8d1f4}{
unsigned char \hyperlink{bus_8c_025b74f1b48eb3c20b99a7158fb8d1f4}{timer\_\-bus\_\-timeout} = 0}
\label{bus_8c_025b74f1b48eb3c20b99a7158fb8d1f4}

\begin{CompactList}\small\item\em Counter that keeps track of how long time ago it was when we received a new character and if it's over the limit we erase all the RX buffer. \item\end{CompactList}\item 
\hypertarget{bus_8c_6e9739c76fabbaee818907fb42a373d4}{
unsigned int \hyperlink{bus_8c_6e9739c76fabbaee818907fb42a373d4}{counter\_\-sync\_\-timeout} = 0}
\label{bus_8c_6e9739c76fabbaee818907fb42a373d4}

\begin{CompactList}\small\item\em Counter that keeps track of how long time ago it was when we received a new SYNC message on the BUS. \item\end{CompactList}\item 
\hypertarget{bus_8c_180f52cd105a2002c6a3209f0ed75440}{
unsigned int \hyperlink{bus_8c_180f52cd105a2002c6a3209f0ed75440}{counter\_\-130us} = 0}
\label{bus_8c_180f52cd105a2002c6a3209f0ed75440}

\begin{CompactList}\small\item\em Counter which keeps track of each time the 130us timer counts up. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
The communication bus protocol used in the openASC project. 

\begin{Desc}
\item[Author:]Mikael Larsmark, SM2WMV \end{Desc}
\begin{Desc}
\item[Date:]2010-01-25 

\begin{Code}\begin{verbatim} #include "wmv_bus/bus.c" 
\end{verbatim}
\end{Code}

 \end{Desc}


Definition in file \hyperlink{bus_8c-source}{bus.c}.

\subsection{Function Documentation}
\hypertarget{bus_8c_8900b6684889df452076e67b3a528bc8}{
\index{bus.c@{bus.c}!bus\_\-add\_\-rx\_\-message@{bus\_\-add\_\-rx\_\-message}}
\index{bus\_\-add\_\-rx\_\-message@{bus\_\-add\_\-rx\_\-message}!bus.c@{bus.c}}
\subsubsection[{bus\_\-add\_\-rx\_\-message}]{\setlength{\rightskip}{0pt plus 5cm}void bus\_\-add\_\-rx\_\-message (unsigned char {\em from\_\-addr}, \/  unsigned char {\em to\_\-addr}, \/  unsigned char {\em flags}, \/  unsigned char {\em cmd}, \/  unsigned char {\em length}, \/  unsigned char {\em data}\mbox{[}$\,$\mbox{]})}}
\label{bus_8c_8900b6684889df452076e67b3a528bc8}


Adds a message to the RX queue which will be sent as soon as possible. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em from\_\-addr}]The address of the sender \item[{\em to\_\-addr}]The address to the receiever \item[{\em flags}]Different flags, see defines \item[{\em cmd}]The command performed \item[{\em length}]The length of the data received \item[{\em data}]The data receieved \end{description}
\end{Desc}


Definition at line 324 of file bus.c.

References BUS\_\-MESSAGE::cmd, BUS\_\-MESSAGE::data, BUS\_\-MESSAGE::flags, BUS\_\-MESSAGE::from\_\-addr, BUS\_\-MESSAGE::length, rx\_\-queue\_\-add(), and BUS\_\-MESSAGE::to\_\-addr.\hypertarget{bus_8c_4c78398b39ca1a317bcd94e32d3238ed}{
\index{bus.c@{bus.c}!bus\_\-add\_\-tx\_\-message@{bus\_\-add\_\-tx\_\-message}}
\index{bus\_\-add\_\-tx\_\-message@{bus\_\-add\_\-tx\_\-message}!bus.c@{bus.c}}
\subsubsection[{bus\_\-add\_\-tx\_\-message}]{\setlength{\rightskip}{0pt plus 5cm}void bus\_\-add\_\-tx\_\-message (unsigned char {\em from\_\-addr}, \/  unsigned char {\em to\_\-addr}, \/  unsigned char {\em flags}, \/  unsigned char {\em cmd}, \/  unsigned char {\em length}, \/  unsigned char {\em data}\mbox{[}$\,$\mbox{]})}}
\label{bus_8c_4c78398b39ca1a317bcd94e32d3238ed}


Adds a message to the TX queue which will be sent as soon as possible. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em from\_\-addr}]The address of the sender \item[{\em to\_\-addr}]The address to the receiever \item[{\em flags}]Different flags, see defines \item[{\em cmd}]The command wanted to be performed \item[{\em length}]The length of the data wanting to be sent \item[{\em data}]The data wanted to be transmitted to the receiever \end{description}
\end{Desc}


Definition at line 291 of file bus.c.

References bus\_\-allowed\_\-to\_\-send(), BUS\_\-CMD\_\-SYNC, BUS\_\-MESSAGE::checksum, BUS\_\-MESSAGE::cmd, BUS\_\-MESSAGE::data, BUS\_\-MESSAGE::flags, BUS\_\-MESSAGE::from\_\-addr, BUS\_\-MESSAGE::length, BUS\_\-MESSAGE::to\_\-addr, and tx\_\-queue\_\-add().

Referenced by antenna\_\-ctrl\_\-deactivate\_\-outputs(), antenna\_\-ctrl\_\-send\_\-ant\_\-data\_\-to\_\-bus(), antenna\_\-ctrl\_\-send\_\-rx\_\-ant\_\-band\_\-data\_\-to\_\-bus(), antenna\_\-ctrl\_\-send\_\-rx\_\-ant\_\-data\_\-to\_\-bus(), band\_\-ctrl\_\-send\_\-band\_\-data\_\-to\_\-bus(), bus\_\-parse\_\-message(), bus\_\-send\_\-ack(), bus\_\-send\_\-nack(), ISR(), main(), send\_\-ping(), and sub\_\-menu\_\-send\_\-data\_\-to\_\-bus().\hypertarget{bus_8c_ceb215ff9ef4810ef00434c1c02f6a4c}{
\index{bus.c@{bus.c}!bus\_\-allowed\_\-to\_\-send@{bus\_\-allowed\_\-to\_\-send}}
\index{bus\_\-allowed\_\-to\_\-send@{bus\_\-allowed\_\-to\_\-send}!bus.c@{bus.c}}
\subsubsection[{bus\_\-allowed\_\-to\_\-send}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char bus\_\-allowed\_\-to\_\-send (void)}}
\label{bus_8c_ceb215ff9ef4810ef00434c1c02f6a4c}


Returns if you are allowed to transmit data to the bus or not. 

\begin{Desc}
\item[Returns:]1 if it's allowed to transmit and 0 if not \end{Desc}


Definition at line 114 of file bus.c.

References BUS\_\-STATUS\_\-MASTER\_\-SENT\_\-SYNC\_\-BIT, and bus\_\-status\_\-struct::flags.

Referenced by bus\_\-add\_\-tx\_\-message(), ISR(), and main().\hypertarget{bus_8c_978d35e07c79199b121997d80de56655}{
\index{bus.c@{bus.c}!bus\_\-get\_\-address@{bus\_\-get\_\-address}}
\index{bus\_\-get\_\-address@{bus\_\-get\_\-address}!bus.c@{bus.c}}
\subsubsection[{bus\_\-get\_\-address}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char bus\_\-get\_\-address (void)}}
\label{bus_8c_978d35e07c79199b121997d80de56655}


Returns the address of this device. 

\begin{Desc}
\item[Returns:]The address of this device \end{Desc}


Definition at line 123 of file bus.c.

References bus\_\-status\_\-struct::ext\_\-addr.

Referenced by antenna\_\-ctrl\_\-deactivate\_\-outputs(), antenna\_\-ctrl\_\-send\_\-ant\_\-data\_\-to\_\-bus(), antenna\_\-ctrl\_\-send\_\-rx\_\-ant\_\-band\_\-data\_\-to\_\-bus(), antenna\_\-ctrl\_\-send\_\-rx\_\-ant\_\-data\_\-to\_\-bus(), band\_\-ctrl\_\-send\_\-band\_\-data\_\-to\_\-bus(), bus\_\-parse\_\-message(), ISR(), main(), send\_\-ping(), and sub\_\-menu\_\-send\_\-data\_\-to\_\-bus().\hypertarget{bus_8c_76f9639571632344a2a1ae4138663667}{
\index{bus.c@{bus.c}!bus\_\-get\_\-device\_\-count@{bus\_\-get\_\-device\_\-count}}
\index{bus\_\-get\_\-device\_\-count@{bus\_\-get\_\-device\_\-count}!bus.c@{bus.c}}
\subsubsection[{bus\_\-get\_\-device\_\-count}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char bus\_\-get\_\-device\_\-count (void)}}
\label{bus_8c_76f9639571632344a2a1ae4138663667}


Receive the device count on the bus. 

\begin{Desc}
\item[Returns:]The number of devices on the bus \end{Desc}


Definition at line 235 of file bus.c.

References bus\_\-status\_\-struct::device\_\-count.

Referenced by main().\hypertarget{bus_8c_ce52a77ee7a62558643de23c5f10f9c7}{
\index{bus.c@{bus.c}!bus\_\-is\_\-master@{bus\_\-is\_\-master}}
\index{bus\_\-is\_\-master@{bus\_\-is\_\-master}!bus.c@{bus.c}}
\subsubsection[{bus\_\-is\_\-master}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char bus\_\-is\_\-master (void)}}
\label{bus_8c_ce52a77ee7a62558643de23c5f10f9c7}


Returns if the bus is set to be master. 

\begin{Desc}
\item[Returns:]1 if it is configured to be master, 0 otherwise \end{Desc}


Definition at line 196 of file bus.c.

References BUS\_\-STATUS\_\-DEVICE\_\-IS\_\-MASTER\_\-BIT, and bus\_\-status\_\-struct::flags.

Referenced by ISR(), and main().\hypertarget{bus_8c_4541ef9a75addac3aaa4af88d8f03590}{
\index{bus.c@{bus.c}!bus\_\-message\_\-nacked@{bus\_\-message\_\-nacked}}
\index{bus\_\-message\_\-nacked@{bus\_\-message\_\-nacked}!bus.c@{bus.c}}
\subsubsection[{bus\_\-message\_\-nacked}]{\setlength{\rightskip}{0pt plus 5cm}void bus\_\-message\_\-nacked (unsigned char {\em addr}, \/  unsigned char {\em error\_\-type})}}
\label{bus_8c_4541ef9a75addac3aaa4af88d8f03590}


The message last sent was NACKED from the receiver. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em addr}]The address of the device that sent the NACK \item[{\em error\_\-type}]Contains information why the message was NACKED \end{description}
\end{Desc}


Definition at line 348 of file bus.c.

References bus\_\-resend\_\-message(), BUS\_\-STATUS\_\-MESSAGE\_\-ACK\_\-TIMEOUT, bus\_\-status\_\-struct::flags, BUS\_\-MESSAGE::to\_\-addr, and tx\_\-queue\_\-get().

Referenced by bus\_\-parse\_\-message(), and event\_\-bus\_\-parse\_\-message().\hypertarget{bus_8c_651be0f483dc1e17174069bbf991d653}{
\index{bus.c@{bus.c}!bus\_\-send\_\-nack@{bus\_\-send\_\-nack}}
\index{bus\_\-send\_\-nack@{bus\_\-send\_\-nack}!bus.c@{bus.c}}
\subsubsection[{bus\_\-send\_\-nack}]{\setlength{\rightskip}{0pt plus 5cm}void bus\_\-send\_\-nack (unsigned char {\em to\_\-addr}, \/  unsigned char {\em error\_\-type})}}
\label{bus_8c_651be0f483dc1e17174069bbf991d653}


Send an NOT acknowledge. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em to\_\-addr}]Which address we wish to send the ping to \item[{\em error\_\-type}]Why was the message nacked, see \hyperlink{bus_8h}{bus.h} for more information about BUS errors \end{description}
\end{Desc}


Definition at line 223 of file bus.c.

References bus\_\-add\_\-tx\_\-message(), BUS\_\-BROADCAST\_\-ADDR, BUS\_\-CMD\_\-NACK, and bus\_\-status\_\-struct::ext\_\-addr.

Referenced by ISR().\hypertarget{bus_8c_9869a6434da36c0bfa8573d68bed9b40}{
\index{bus.c@{bus.c}!bus\_\-set\_\-address@{bus\_\-set\_\-address}}
\index{bus\_\-set\_\-address@{bus\_\-set\_\-address}!bus.c@{bus.c}}
\subsubsection[{bus\_\-set\_\-address}]{\setlength{\rightskip}{0pt plus 5cm}void bus\_\-set\_\-address (unsigned char {\em addr})}}
\label{bus_8c_9869a6434da36c0bfa8573d68bed9b40}


Set the address of this device on the bus. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em addr}]The address of this device \end{description}
\end{Desc}


Definition at line 108 of file bus.c.

References bus\_\-status\_\-struct::ext\_\-addr.

Referenced by main().\hypertarget{bus_8c_bbcb4456ec66651e191189cc985bfeab}{
\index{bus.c@{bus.c}!bus\_\-set\_\-device\_\-count@{bus\_\-set\_\-device\_\-count}}
\index{bus\_\-set\_\-device\_\-count@{bus\_\-set\_\-device\_\-count}!bus.c@{bus.c}}
\subsubsection[{bus\_\-set\_\-device\_\-count}]{\setlength{\rightskip}{0pt plus 5cm}void bus\_\-set\_\-device\_\-count (unsigned char {\em device\_\-count})}}
\label{bus_8c_bbcb4456ec66651e191189cc985bfeab}


Set the number of devices that are on the bus. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em device\_\-count}]The number of devices on the bus, ie the number of time slots \end{description}
\end{Desc}


Definition at line 241 of file bus.c.

References BUS\_\-TIME\_\-MULTIPLIER, bus\_\-status\_\-struct::device\_\-count, and bus\_\-status\_\-struct::device\_\-count\_\-mult.\hypertarget{bus_8c_ed493aabe32ac3eaafb77d4c23f15eb9}{
\index{bus.c@{bus.c}!bus\_\-set\_\-is\_\-master@{bus\_\-set\_\-is\_\-master}}
\index{bus\_\-set\_\-is\_\-master@{bus\_\-set\_\-is\_\-master}!bus.c@{bus.c}}
\subsubsection[{bus\_\-set\_\-is\_\-master}]{\setlength{\rightskip}{0pt plus 5cm}void bus\_\-set\_\-is\_\-master (unsigned char {\em state}, \/  unsigned char {\em count})}}
\label{bus_8c_ed493aabe32ac3eaafb77d4c23f15eb9}


Set the status if the device should be master or not. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em state}]1 if you wish the device to be master, 0 if you wish that it should be slave \item[{\em count}]The nr of devices \end{description}
\end{Desc}


Definition at line 206 of file bus.c.

References BUS\_\-STATUS\_\-ALLOWED\_\-TO\_\-SEND\_\-BIT, BUS\_\-STATUS\_\-DEVICE\_\-IS\_\-MASTER\_\-BIT, BUS\_\-STATUS\_\-FORCE\_\-SYNC, BUS\_\-TIME\_\-MULTIPLIER, bus\_\-status\_\-struct::device\_\-count, bus\_\-status\_\-struct::device\_\-count\_\-mult, and bus\_\-status\_\-struct::flags.

Referenced by main().\hypertarget{bus_8c_90fe1670ecc0478c38c6903ffa1fb1ac}{
\index{bus.c@{bus.c}!ISR@{ISR}}
\index{ISR@{ISR}!bus.c@{bus.c}}
\subsubsection[{ISR}]{\setlength{\rightskip}{0pt plus 5cm}ISR (ISR\_\-BUS\_\-TIMER\_\-COMPARE)}}
\label{bus_8c_90fe1670ecc0478c38c6903ffa1fb1ac}


Timer interrupt with $\sim$130us intervals 

Definition at line 512 of file bus.c.

References BUS\_\-ACK\_\-WRAPAROUND\_\-LIMIT, bus\_\-is\_\-master(), bus\_\-resend\_\-message(), bus\_\-reset\_\-rx\_\-status(), BUS\_\-STATUS\_\-MASTER\_\-SENT\_\-SYNC\_\-BIT, BUS\_\-STATUS\_\-MESSAGE\_\-ACK\_\-TIMEOUT, BUS\_\-STATUS\_\-TIME\_\-SLOT\_\-ACTIVE, BUS\_\-SYNC\_\-TIMEOUT\_\-LIMIT, BUS\_\-TIMEOUT\_\-LIMIT, counter\_\-130us, counter\_\-sync\_\-timeout, bus\_\-status\_\-struct::device\_\-count, bus\_\-status\_\-struct::device\_\-count\_\-mult, ERROR\_\-TYPE\_\-BUS\_\-SYNC, event\_\-set\_\-error(), bus\_\-status\_\-struct::flags, bus\_\-status\_\-struct::frame\_\-counter, led\_\-set\_\-error(), LED\_\-STATE\_\-ON, bus\_\-status\_\-struct::lower\_\-limit, timer\_\-bus\_\-timeout, tx\_\-queue\_\-dropall(), bus\_\-status\_\-struct::upper\_\-limit, and bus\_\-status\_\-struct::wraparounds.\hypertarget{bus_8c_efcb4b9972f80d02e113869d694b4aab}{
\index{bus.c@{bus.c}!ISR@{ISR}}
\index{ISR@{ISR}!bus.c@{bus.c}}
\subsubsection[{ISR}]{\setlength{\rightskip}{0pt plus 5cm}ISR (ISR\_\-BUS\_\-USART\_\-TRANS)}}
\label{bus_8c_efcb4b9972f80d02e113869d694b4aab}


USART data transmit interrupt 

Definition at line 506 of file bus.c.

References BUS\_\-STATUS\_\-RECEIVE\_\-ON, BUS\_\-STATUS\_\-SEND\_\-ACTIVE, and bus\_\-status\_\-struct::flags.\hypertarget{bus_8c_4ea7bd97e74a54718958107b4d2da063}{
\index{bus.c@{bus.c}!ISR@{ISR}}
\index{ISR@{ISR}!bus.c@{bus.c}}
\subsubsection[{ISR}]{\setlength{\rightskip}{0pt plus 5cm}ISR (ISR\_\-BUS\_\-USART\_\-RECV)}}
\label{bus_8c_4ea7bd97e74a54718958107b4d2da063}


USART data receive interrupt 

Definition at line 386 of file bus.c.

References bus\_\-add\_\-new\_\-message(), BUS\_\-BROADCAST\_\-ADDR, BUS\_\-CHECKSUM\_\-ERROR, BUS\_\-CMD\_\-PING, BUS\_\-CMD\_\-SYNC, BUS\_\-MESSAGE\_\-FLAGS\_\-NEED\_\-ACK, bus\_\-ping\_\-new\_\-stamp(), bus\_\-reset\_\-rx\_\-status(), bus\_\-send\_\-ack(), bus\_\-send\_\-nack(), BUS\_\-STATUS\_\-ALLOWED\_\-TO\_\-SEND\_\-BIT, BUS\_\-STATUS\_\-MASTER\_\-SENT\_\-SYNC\_\-BIT, BUS\_\-STATUS\_\-PREAMBLE\_\-FOUND\_\-BIT, BUS\_\-STATUS\_\-RECEIVE\_\-ON, BUS\_\-TIME\_\-MULTIPLIER, calc\_\-checksum, bus\_\-status\_\-struct::char\_\-count, BUS\_\-MESSAGE::checksum, BUS\_\-MESSAGE::cmd, counter\_\-sync\_\-timeout, BUS\_\-MESSAGE::data, bus\_\-status\_\-struct::device\_\-count, bus\_\-status\_\-struct::device\_\-count\_\-mult, bus\_\-status\_\-struct::ext\_\-addr, BUS\_\-MESSAGE::flags, bus\_\-status\_\-struct::flags, bus\_\-status\_\-struct::frame\_\-counter, BUS\_\-MESSAGE::from\_\-addr, BUS\_\-MESSAGE::length, bus\_\-status\_\-struct::prev\_\-char, timer\_\-bus\_\-timeout, and BUS\_\-MESSAGE::to\_\-addr.\hypertarget{bus_8c_56c7d1c90fd3b9b05b882677670d151e}{
\index{bus.c@{bus.c}!ISR@{ISR}}
\index{ISR@{ISR}!bus.c@{bus.c}}
\subsubsection[{ISR}]{\setlength{\rightskip}{0pt plus 5cm}ISR (ISR\_\-BUS\_\-USART\_\-DATA)}}
\label{bus_8c_56c7d1c90fd3b9b05b882677670d151e}


USART data interrupt 

Definition at line 381 of file bus.c.